import { session } from 'js/util'
export default {
  state: {
    // 分类名称
    className: '',
    // 商品新增产生的Id
    goodsId: (sessionStorage.getItem('goodsId') || ''),
    // 颜色规格
    colorSpescList: (session.get('colorList') || []),
    // 上传过的规格图片
    oldFileNameGsp: (session.get('oldFileNameGsp') || []),
    // 已上传的主图
    photoInfo: (session.get('photoInfo') || []),
    photoInfoUrl: (sessionStorage.getItem('photoInfoUrl') || ''),
    photoMainUrl: (sessionStorage.getItem('photoMainUrl') || ''),
    photoMain: (sessionStorage.getItem('photoMain') || ''),
    photoGspUrl: (sessionStorage.getItem('photoGspUrl') || ''),
    // 商品详情里面的产品参数
    features: [],
    // 商品详情里面的富文本
    goodsDetails: (sessionStorage.getItem('goodsDetails') || ''),
    // 商品规格组合
    goodsInventoryDetail: (sessionStorage.getItem('goodsInventoryDetail') || ''),
    // 保存编辑还是新增进入本页
    intoThisPage: (sessionStorage.getItem('intoThisPage') || 1),
    // 保存编辑还是新增进入本页后返回上一页
    intoNextPage: (sessionStorage.getItem('intoNextPage') || ''),
    // 颜色规格
    goodsDetailsList: (session.get('goodsDetailsList') || [])
  },
  getters: {
    getClassName: state => state.className,
    goodsId: state => state.goodsId,
    colorSpescList: state => state.colorSpescList,
    photoInfo: state => state.photoInfo,
    photoInfoUrl: state => state.photoInfoUrl,
    photoMainUrl: state => state.photoMainUrl,
    photoMain: state => state.photoMain,
    photoGspUrl: state => state.photoGspUrl,
    feature: state => state.features,
    goodsDetails: state => state.goodsDetails,
    goodsInventoryDetail: state => state.goodsInventoryDetail,
    intoThisPage: state => state.intoThisPage,
    intoNextPage: state => state.intoNextPage,
    goodsDetailsList: state => state.goodsDetailsList
  },
  actions: {
    intoNextPage(context, intoNextPage) {
      context.commit('intoNextPage', intoNextPage)
    },
    goodsDetailsList(context, goodsDetailsList) {
      context.commit('goodsDetailsList', goodsDetailsList)
    },
    updateGoodsId(context, goodsId) {
      context.commit('updateGoodsId', goodsId)
    },
    intoThisPage(context, intoThisPage) {
      context.commit('intoThisPage', intoThisPage)
    },
    goodsInventoryDetail(context, goodsInventoryDetail) {
      context.commit('goodsInventoryDetail', goodsInventoryDetail)
    },
    updateColorSpesc(context, colorList) {
      context.commit('updateColorSpesc', colorList)
    },
    photoInfo(context, photoInfo) {
      context.commit('photoInfo', photoInfo)
    },
    photoGspUrl(context, photoGspUrl) {
      context.commit('photoGspUrl', photoGspUrl)
    },
    photoInfoUrl(context, photoInfoUrl) {
      context.commit('photoInfoUrl', photoInfoUrl)
    },
    photoMainUrl(context, photoMainUrl) {
      context.commit('photoMainUrl', photoMainUrl)
    },
    photoMain(context, photoMain) {
      context.commit('photoMain', photoMain)
    },
    feature(context, features) {
      context.commit('features', features)
    },
    goodsDetails(context, goodsDetails) {
      context.commit('goodsDetails', goodsDetails)
    },
    // 清除信息
    clearAddGoodsInfo(state) {
      session.remove('goodsId')
      session.remove('colorSpescList')
      session.remove('oldFileNameGsp')
      session.remove('photoInfo')
      session.remove('photoMainUrl')
      session.remove('photoMain')
      session.remove('goodsDetails')
      session.remove('goodsInventoryDetail')
      session.remove('intoThisPage')
      session.remove('photoInfoUrl')
      session.remove('intoNextPage')
      session.remove('goodsDetailsList')
      session.remove('photoGspUrl')
      session.remove('crowdfundingCount')
      session.remove('goodsNumType')
      state.goodsId = ''
      state.colorSpescList = []
      state.oldFileNameGsp = []
      state.photoGspUrl = ''
      state.photoInfo = []
      state.goodsDetailsList = []
      state.photoMainUrl = ''
      state.photoMain = ''
      state.goodsDetails = ''
      state.photoInfoUrl = ''
      state.goodsInventoryDetail = []
      state.intoThisPage = 1
      state.features = ''
      state.intoNextPage = ''
    }
  },
  mutations: {
    updateGoodsId(state, goodsId) {
      session.set('goodsId', goodsId)
      state.goodsId = goodsId
    },
    goodsDetailsList(state, goodsDetailsList) {
      goodsDetailsList.forEach((v) => {
        v.oldFileNameGsp = ''
      })
      session.set('goodsDetailsList', goodsDetailsList)
      state.goodsDetailsList = goodsDetailsList
    },
    updateColorSpesc(state, colorList) {
      state.colorSpescList = []
      session.set('colorSpescList', colorList)
      state.colorSpescList = state.colorSpescList.concat(colorList)
    },
    photoInfo(state, photoInfo) {
      session.set('photoInfo', photoInfo)
       state.photoInfo = photoInfo
    },
    photoGspUrl(state, photoGspUrl) {
      session.set('photoGspUrl', photoGspUrl)
       state.photoGspUrl = photoGspUrl
    },
    intoThisPage(state, intoThisPage) {
      session.set('intoThisPage', intoThisPage)
      state.intoThisPage = intoThisPage
    },
    intoNextPage(state, intoNextPage) {
      session.set('intoNextPage', intoNextPage)
      state.intoNextPage = intoNextPage
    },
    goodsInventoryDetail(state, goodsInventoryDetail) {
      session.set('goodsInventoryDetail', goodsInventoryDetail)
       state.goodsInventoryDetail = goodsInventoryDetail
    },
    photoInfoUrl(state, photoInfoUrl) {
      session.set('photoInfoUrl', photoInfoUrl)
      state.photoInfoUrl = photoInfoUrl
    },
    photoMainUrl(state, photoMainUrl) {
      session.set('photoMainUrl', photoMainUrl)
      state.photoMainUrl = photoMainUrl
    },
    photoMain(state, photoMain) {
      session.set('photoMain', photoMain)
      state.photoMain = photoMain
    },
    feature(state, features) {
      state.features = features
    },
     goodsDetails(state, goodsDetails) {
      session.set('goodsDetails', goodsDetails)
      state.goodsDetails = goodsDetails
    },
    // 清除信息
    clearAddGoodsInfo(state) {
      session.remove('goodsId')
      session.remove('colorSpescList')
      session.remove('oldFileNameGsp')
      session.remove('photoInfo')
      session.remove('photoMainUrl')
      session.remove('photoMain')
      session.remove('goodsDetails')
      session.remove('goodsInventoryDetail')
      session.remove('intoThisPage')
      session.remove('photoInfoUrl')
      session.remove('intoNextPage')
      session.remove('goodsDetailsList')
      session.remove('photoGspUrl')
      session.remove('crowdfundingCount')
      session.remove('goodsNumType')
      state.goodsId = ''
      state.colorSpescList = []
      state.oldFileNameGsp = []
      state.photoGspUrl = ''
      state.photoInfo = []
      state.goodsDetailsList = []
      state.photoMainUrl = ''
      state.photoMain = ''
      state.goodsDetails = ''
      state.photoInfoUrl = ''
      state.goodsInventoryDetail = []
      state.intoThisPage = 1
      state.features = ''
      state.intoNextPage = ''
    }
  }
}
